import { GeneraDataType } from "@/interface";
import { updatePreOrderShipmentAgentChannelApi } from "@/api/waybillManagement/customerServiceWaybill";
import { message } from "ant-design-vue";
import FormHook from "@/hook/formHook";

export default function OperationHook(state: GeneraDataType) {
  const { formDataRef, formState, passData, emit, loading } = state;
  const { resetFields } = FormHook({ formState });

  const onFinish = () => {
    const params = {
      ...formState,
      id: passData.value.id
    };
    loading.value = true;
    updatePreOrderShipmentAgentChannelApi(params)
      .then((res: any) => {
        const { code } = res;
        if (code === 200) {
          message.success("操作成功!");
          emit("submit");
        }
      })
      .finally(() => (loading.value = false));
  };
  const onFinishFailed = (errorInfo: any) => {
    console.log("Failed:", errorInfo);
  };

  const resetHandle = () => {
    resetFields();
    formDataRef.value.clearValidate();
    emit("update:visible", false);
  };
  return { onFinish, resetHandle, onFinishFailed, resetFields };
}
